<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .default {
            width: 100px;
            height: 100px;
            background: green;
        }
    </style>
</head>
<body>
    <div id="app">
        <button @click="show">显示</button>
        <button @click="hide">隐藏</button>
        <button @click="toggle">切换</button>
        <button @click="toggleBg">切换颜色</button>

        <div v-show="visible" :style="{background: bgVisible ? 'red' : 'green'}" class="default"></div>
    </div>

    <script src="./vue.js"></script>
    <script>
        // 数据驱动
        let myApp = new Vue({
            el: '#app',
            data: {
                visible: true,
                bgVisible: false
            },
            methods: {
                show () {
                    this.visible = true
                },
                hide () {
                    this.visible = false
                },
                toggle () {
                    this.visible = !this.visible
                },
                toggleBg () {
                    this.bgVisible = !this.bgVisible
                }
            }
        })
    </script>
</body>
</html>